package stu.day19_day24.day22;

import java.util.Scanner;

public class hw1 {


    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        String target = sc.nextLine();
        String source = sc.nextLine();
        
        int num = 0;
        int index = 0;
        int tep = 0;

        for(int i=0;i<source.length();i++){
            char c = source.charAt(i);
            
            
            if(c==target.charAt(num) && num==0){
                tep = i;
                num += 1;
                continue;
            } else if (c==target.charAt(num) && num==(target.length()-1)) {
                index = tep;
                num =0;
                continue;
            } else if (c==target.charAt(num)) {
                num += 1;
            }

        }


        System.out.println(index);

        
    }
}

